package homeWork.Three.demo4;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-11-30
 * Time: 17:22
 */
public class TestDemo {

    public static void bubble_sort(int[] arr){
        for(int i =0;i<arr.length-1;++i){
            for(int j = 0;j< arr.length-1-i;++j){
                if(arr[j]>arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        //1．要求用户输入若干整数，使用冒泡排序法实现其从小到大的排序，并输入排序后的结果。
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入10个你想要排序的数字");
        int[] arr = new int[5];
        for(int i =0;i<5;++i){
            arr[i] = scanner.nextInt();
        }
        bubble_sort(arr);
        System.out.println(Arrays.toString(arr));
    }

}
